#include "bitset.h"
#include <iostream>

using namespace std;

uint64_t BitSet::masks[ 64 ] = {
  1ul, 
  2ul, 
  4ul, 
  8ul, 
  16ul, 
  32ul, 
  64ul, 
  128ul, 
  256ul, 
  512ul, 
  1024ul, 
  2048ul, 
  4096ul, 
  8192ul, 
  16384ul, 
  32768ul, 
  65536ul, 
  131072ul, 
  262144ul, 
  524288ul, 
  1048576ul, 
  2097152ul, 
  4194304ul, 
  8388608ul, 
  16777216ul, 
  33554432ul, 
  67108864ul, 
  134217728ul, 
  268435456ul, 
  536870912ul, 
  1073741824ul, 
  2147483648ul, 
  4294967296ul, 
  8589934592ul, 
  17179869184ul, 
  34359738368ul, 
  68719476736ul, 
  137438953472ul, 
  274877906944ul, 
  549755813888ul, 
  1099511627776ul, 
  2199023255552ul, 
  4398046511104ul, 
  8796093022208ul, 
  17592186044416ul, 
  35184372088832ul, 
  70368744177664ul, 
  140737488355328ul, 
  281474976710656ul, 
  562949953421312ul, 
  1125899906842624ul, 
  2251799813685248ul, 
  4503599627370496ul, 
  9007199254740992ul, 
  18014398509481984ul, 
  36028797018963968ul, 
  72057594037927936ul, 
  144115188075855872ul, 
  288230376151711744ul, 
  576460752303423488ul, 
  1152921504606846976ul, 
  2305843009213693952ul, 
  4611686018427387904ul, 
};

// BitSet8
BitSet8::BitSet8() : array( 0 ) {}

inline int BitSet8::length() {
  return 8;
}

inline void BitSet8::set( int index, bool value ) {
  if( value )
    array |= masks[ index ];
  else if( get( index ) )
    array ^= masks[ index ];
}

inline bool BitSet8::get( int index ) {
  return array & masks[ index ];
}

inline void BitSet8::print() {
  for( int i = 7; i >= 0 ; i-- )
    cout << ( ( array & masks[ i ] ) ? '1' : '0' );
  cout << endl;
}

// BitSet16
BitSet16::BitSet16() : array( 0 ) {}

inline int BitSet16::length() {
  return 16;
}

inline void BitSet16::set( int index, bool value ) {
  if( value )
    array |= masks[ index ];
  else if( get( index ) )
    array ^= masks[ index ];
}

inline bool BitSet16::get( int index ) {
  return array & masks[ index ];
}

inline void BitSet16::print() {
  for( int i = 15; i >= 0 ; i-- )
    cout << ( ( array & masks[ i ] ) ? '1' : '0' );
  cout << endl;
}

// BitSet32
BitSet32::BitSet32() : array( 0 ) {}

inline int BitSet32::length() {
  return 32;
}

inline void BitSet32::set( int index, bool value ) {
  if( value )
    array |= masks[ index ];
  else if( get( index ) )
    array ^= masks[ index ];
}

inline bool BitSet32::get( int index ) {
  return array & masks[ index ];
}

inline void BitSet32::print() {
  for( int i = 31; i >= 0 ; i-- )
    cout << ( ( array & masks[ i ] ) ? '1' : '0' );
  cout << endl;
}

// BitSet 64
BitSet64::BitSet64() : array( 0 ) {}

inline int BitSet64::length() {
  return 64;
}

inline void BitSet64::set( int index, bool value ) {
  if( value )
    array |= masks[ index ];
  else if( get( index ) )
    array ^= masks[ index ];
}

inline bool BitSet64::get( int index ) {
  return array & masks[ index ];
}

inline void BitSet64::print() {
  for( int i = 63; i >= 0 ; i-- )
    cout << ( ( array & masks[ i ] ) ? '1' : '0' );
  cout << endl;
}
